package com.zr.daoimpl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.ShowAllStationDao;
import com.zr.model.Cdisstation;
import com.zr.model.Cstationtype;
import com.zr.model.Cuser;

@Repository("showAllStationDao")
public class ShowAllStationDaoImpl<T> extends BaseDaoImpl<T> implements ShowAllStationDao<T>{

	@Override
	public int getStationCount(int ids) {
		int n = 0;
	     String hql = "from Cdisstation where disid not in (:ids)";
	     Query que = this.getCurrentSession().createQuery(hql);
	     que.setInteger("ids", ids);
	    List<Cuser> us = que.list();
	     n = us.size();
		return n;
	}

	@Override
	public List<Cdisstation> getAllStations(int page, int rows,int ids) {
        List<Cdisstation> stations = new ArrayList<Cdisstation>();
		String hql="from Cdisstation where disid not in (:ids)";
	    Query que=this.getCurrentSession().createQuery(hql);
	    que.setInteger("ids", ids);
	    que.setFirstResult((page-1)*rows);
		que.setMaxResults(rows);
		stations = que.list();
		return stations;
	}

	@Override
	public String getStationNameByDisid(int disid) {
		 String s = new String();
	     String hql = "from Cdisstation where disid = :disid";
	     Query que = this.getCurrentSession().createQuery(hql);
	     que.setInteger("disid", disid);
	    List<Cdisstation> us = que.list();
	     s = us.get(0).getDisname();
		return s;
	}

	@Override
	public int getStationIdByDisid(int disid) {
		 int s = 0;
	     String hql = "from Cdisstation where disid = :disid";
	     Query que = this.getCurrentSession().createQuery(hql);
	     que.setInteger("disid", disid);
	    List<Cdisstation> us = que.list();
	     s = us.get(0).getDisid();
		return s;
	}


}
